package org.bees.cms.web.util;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;

import javax.persistence.Column;

import org.bees.cms.core.clause.Adapter;

public class JPAAdapter implements Adapter {

	@Override
	public String adapt(Class<?> mapper, String property, String alias) throws Exception {
		PropertyDescriptor descriptor = new PropertyDescriptor(property, mapper);
		Method method = descriptor.getReadMethod();
		Column column = method.getAnnotation(Column.class);
		String name = column == null ? null : column.name();
		return name == null || name.equals("") ? property : name;
	}

}
